WDV221 Intro Javascript
Lab Exam #1
Please do your work inside this page. You are welcome to modify the html of this page as needed for the project.
1. Define a global variable called studentName and assign your name to the field.
2. Define a global variable called courseName and assign the course name "WDV221 Intro to Javascript" to the variable.
3. Define a global variable called totalSales and assign it an initial value of 0.
4. Create a runtime script that will display studentName as an H1 element and the courseName as an H2 element above the form.
5. Use javascript to display the value of the studentName variable where yourName is currently displayed.
6. Change one of the submit buttons to "Calculate Sale". Apply an event handler to call the computeCost function.
7. Change the other button to a reset button.
8. Create a function called computeCost. The computeCost function should do the following things:
- Create a local variable called itemPrice. Initialize it to zero. Take the information entered in the Item Price textfield and place it in the variable.
- Create a local variable called numberPurchased. Initialize it to zero Take the information entered in the Number Purchased textfield and place it in the variable.
- Create a local variable called salePrice.
- The function should multiply itemPrice * numberPurchased and assign it to salePrice.
- Display the value of salePrice in the textfield next to the words Sale Price:
- Use the combined operator to add salePrice to totalSales. This will be the running total for the order.
- Display the value of the totalSales variable next the words Total Sales:. Use .innerHTML to make this happen.
Note: Even if you do not complete the function make sure it runs without breaking. Partial credit will be given for any work that runs corectly.
Extra Credit:
- Insert a textfield and a descirption called Sales Tax:
- Calculate the Iowa sales tax of 6% on the salePrice variable.
- Display the sales tax amount next to the Sales Tax: words. Use .innerHTML to make this happen.
- Add the sales tax amount to the salePrice before adding the sale amount to totalSales.